// 获取页面滚动距离方法
import { onMounted, onUnmounted, ref } from "vue";

export default function useScrollTop() {
  // 定义滚动距离
  const scroll = ref(0);
  // 获取滚动距离
  const scrollHandle = () => {
    scroll.value = document.documentElement.scrollTop;
  };
  // 组件安装时触发方法获取滚动距离
  onMounted(() => {
    window.addEventListener("scroll", scrollHandle);
  });
  // 组件卸载时删除方法
  onUnmounted(() => {
    window.removeEventListener("scroll", scrollHandle);
  });
  return scroll;
}
